From 8a90781bf8c87f634019a6e66570c3d792edd0e0 Mon Sep 17 00:00:00 2001 From: "mjw@wray-m-3.hpl.hp.com" Date: Fri, 30 Jul 2004 08:49:23 +0000 Subject: [PATCH] bitkeeper revision 1.1108.35.7 (410a0b93obztTzgYAKS6IcEBh3xJcQ) Use environment variables XEND and XEND_ROOT to set the location of the xend server and its root path. --- tools/python/xen/xend/XendClient.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tools/python/xen/xend/XendClient.py b/tools/python/xen/xend/XendClient.py index 1bb7a094f2..cc5b06fd10 100644 --- a/tools/python/xen/xend/XendClient.py +++ b/tools/python/xen/xend/XendClient.py @@ -9,6 +9,7 @@ The 'data-plane' is done separately. For example, consoles are accessed via sockets on xend, but the list of consoles is accessible via this API. """ +import os import sys import httplib import types @@ -331,9 +332,15 @@ class Xend: """Default location of the xend server.""" SRV_DEFAULT = "localhost:8000" + """Environment variable to set the location of xend.""" + SRV_VAR = "XEND" + """Default path to the xend root on the server.""" ROOT_DEFAULT = "/xend/" + """Environment variable to set the xend root path.""" + ROOT_VAR = "XEND_ROOT" + def __init__(self, client=None, srv=None, root=None): """Create a xend client interface. If the client protocol is not specified, the default @@ -348,14 +355,24 @@ class Xend: self.client = client self.bind(srv, root) + def default_server(self): + """Get the default location of the xend server. + """ + return os.getenv(self.SRV_VAR, self.SRV_DEFAULT) + + def default_root(self): + """Get the default root path on the xend server. + """ + return os.getenv(self.ROOT_VAR, self.ROOT_DEFAULT) + def bind(self, srv=None, root=None): """Bind to a given server. @param srv: server location (host:port) @param root: xend root path on the server """ - if srv is None: srv = self.SRV_DEFAULT - if root is None: root = self.ROOT_DEFAULT + if srv is None: srv = self.default_server() + if root is None: root = self.default_root() if not root.endswith('/'): root += '/' (host, port) = srv.split(':', 1) self.url = URL(host=host, port=port, path=root) -- 2.30.2